function showVehicleTravelStrategySearch() {
	window.location.href = "showImportantVehicleSearch.do";
}

function ajaxFindVehicleTravelStrategySearchList(currentPage,pageSize) {
	$.ajax({
		type : "post",
		url : "ajaxVehicleTravelStrategySearchList.do",
		data : {
			name:$("#scName").val(),
			signalstate:$("#scSignalLampStatus").val(),
			direction:$("#scTravelDirection").val(),
			canmove:$("#scCanMove").val(),
			currentPage:currentPage,
			pageSize:pageSize,
		},
		success : function(msg) {
			$("#listVehicleTravelStrategyBox").html(msg);
		}
	});
}

function ajaxShowVehicleTravelStrategyEdit(id){
	$.ajax({
		type:"post",
		url:"ajaxShowVehicleTravelStrategyEdit.do",
		data:{vehicleTravelStrategyId:id},
		success:function(msg){
			$("#dialog").html(msg);
			$("#dialog").dialog({
				autoOpen: true,
				width: 680,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons: [
				          {
				        	  text: "保存",
				        	  click: function() {
				        		  ajaxSaveVehicleTravelStrategy(this);
				        	  }
				          },
				          {
				        	  text: "关闭",
				        	  click: function() {
				        		  $(this).dialog( "close" );
				        	  }
				          }
				          ]
			});
		}
	});
}

function ajaxSaveVehicleTravelStrategy(objDialog) {
	vehicleTravelStrategyValidate();
	if ($("#frmVehicleTravelStrategy").valid()) {
		$(objDialog).dialog("close");
		var options ={
				type: "post",
				url : "ajaxSaveVehicleTravelStrategy.do",
				success: function () {
					clearInput("#sltVehicleTravelStrategy");
					ajaxFindVehicleTravelStrategySearchList();
					showMessageDialog("保存车辆行驶策略信息","车辆行驶策略信息保存成功。",null,dialogType.info);
				}
		};
		$("#frmVehicleTravelStrategy").ajaxSubmit(options);
	}
}

function ajaxDeleteVehicleTravelStrategyById(id) {
	var vehicleTravelStrategyIds="";
	var sltVTS = $("#listVehicleTravelStrategyList tbody input:checked").length;
	if(id==null){
		$("#listVehicleTravelStrategyList tbody input:checked").each(function(){ 
			vehicleTravelStrategyIds += $(this).val()+";";
		});
		if(sltVTS == 0){
			showMessageDialog("提示","请选择一行或多行",null,dialogType.info);
			return;
		}else{
			vehicleTravelStrategyIds = vehicleTravelStrategyIds.substring(0, vehicleTravelStrategyIds.length-1);
		} 
	}else{
		vehicleTravelStrategyIds=id;
		sltVTS = 1;
	}
	if( vehicleTravelStrategyIds!=null){
		showMessageDialog("删除车辆行驶策略信息","确定要删除所选“"+sltVTS+"”条车辆行驶策略信息记录吗？",
				function () {
			$.ajax({     
				type:"post",
				url:"ajaxDeleteVehicleTravelStrategyByIds.do",
				data:{vehicleTravelStrategyIds:vehicleTravelStrategyIds},
				success:function(msg){
					ajaxFindVehicleTravelStrategySearchList();
					showMessageDialog("提示","车辆行驶策略信息删除成功",null,dialogType.info);
				}
			});
		}
		,dialogType.warning);
	}
}

function vehicleTravelStrategyValidate(){
	$("#frmVehicleTravelStrategy").validate({
		errorLabelContainer: $("#infoVehicleTravelStrategy"),
		rules : {
			name : {
				required :true				
			},
			signalstate : {
				required :true				
			},
			direction : {
				required :true
			},
			canmove : {
				required :true
			}
		},
		messages : {
			name : {
				required :"请输入名称！"
			},
			signalstate : {
				required :"请输入信号灯状态！"
			},
			direction : {
				required :"请输入行驶方向！"
			},
			canmove : {
				required :"是否可继续通行！"
			}
		},
		success: function(label) {
			label.html("&nbsp;");
		}
	});
}
